/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2024-04-04
 * Time: 19:04
 */
import java.util.*;
public class Test2 {
   //力扣——有效的括号
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for(int i = 0;i < s.length();i++){
            char ch = s.charAt(i);
            if(ch =='['||ch == '('||ch=='{'){
                stack.push(ch);
            }
            else{
                if(stack.empty()){
                    return false;
                }
                if(stack.peek() == '('&&ch == ')'||stack.peek() == '['&&ch == ']'||stack.peek() == '{'&&ch == '}' ){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }
        return stack.empty();
    }
}
